<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加商户</title>
<link rel="stylesheet" href="${base}/static/media/css/bootstrap.css" />
<script src="${base}/static/index/vendor/jquery/jquery.min.js"></script>
<script src="${base}/static/index/vendor/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" charset="utf-8" src="${base }/static/vendor/bootstrapPager/bootstrapPager.js"></script>
<script type="text/javascript" charset="utf-8" src="${base }/static/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" charset="utf-8" src="${base }/static/js/layer/layer.js"></script>
<link href="${base }/static/css/base.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="${base }/static/css/help.css" />
<script type="text/javascript" src="${base }/static/js/jquery-1.8.1.min.js"></script> 
<script type="text/javascript" charset="utf-8" src="${base }/static/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">

$(document).ready(function(){

    var s = $("input[name='nation']");
    s.each(function(i) {
//          alert(i);
        $(this).click(function(){
            if(this.checked==true){
                $('#cardp'+this.value).show();
            }else{
                $('#cardp'+this.value).hide();
            }
        });
    });
    $("#submitButton").click(function(){
        var releaseTime = $("input[name=releaseTime]").val();//释放日期
        var releaseAmount = $("input[name=releaseAmount]").val();//释放金额
        var isCheck = true;
        var nationArr = new Array();
        var tkStr = ""; 
        var tkNum = 0;
        $("input[name='nation']").each(function(i){
            if($(this).prop("checked")){
                nationArr[i] = i;
                var cardps = $("input[name=cardps"+i+"]").val();
                var cardpe = $("input[name=cardpe"+i+"]").val();
                if(cardps==""||cardpe==""||cardpe<cardps){
                    layer.msg("请输入正确的卡号区间");
                    isCheck = false;
                    return false;
                }else{
                    if(i==0){
                        tkStr += '<p>面额1000:'+(cardpe-cardps+1)+'张</p>';
                        tkNum += (cardpe-cardps+1)*1000;
                    }
                    if(i==1){
                        tkStr += '<p>面额500:'+(cardpe-cardps+1)+'张</p>';
                        tkNum += (cardpe-cardps+1)*500;
                    }
                    if(i==2){
                        tkStr += '<p>面额100:'+(cardpe-cardps+1)+'张</p>';
                        tkNum += (cardpe-cardps+1)*100;
                    }
                }
            }
        });
        if(nationArr==""){
            layer.msg("请选择充值卡面额");
            isCheck = false;
            return false;
        }
        if($.isNumeric(releaseAmount)==false||releaseAmount==""){
            layer.msg("请输入正确的释放金额");
            isCheck = false;
            return false;
        }
        if(releaseTime==""){
            layer.msg("请输入释放日期");
            isCheck = false;
            return false;
        }
        if(releaseAmount!=tkNum){
            layer.msg("您输入的释放金额与充值卡面额之和不符");
            isCheck = false;
            return false;
        }
        if(isCheck==true){
            layer.confirm(tkStr+'确定释放吗?', {icon: 3, title:'提示'}, function(index){
                debugger;
                layer.close(index);
                $("#submitButton").hide();
                $("#submitShow").show();
                var data = $("#orderlist_form").serializeArray();
                $.ajax({
                    url:"${pageContext.request.contextPath}/buyOil/addOilCustomerRelease",
                    type:'post',
                    dataType:'json',
                    data:data,
                    success:function(res)
                    {
                    	debugger;
                    	/* alert(res.code);
                    	alert("成功") */
                        if(res.code==1){
                           /*  layer.msg(res.msg, {icon: 1}); */
                           /*  var id = $("#id").val();
	                      	window.parent.href="${pageContext.request.contextPath}/buyOil/calculateOil?id=" + id; */
                        }else{
                            /* layer.msg(res.msg, {icon: 5}); */
                        }
                        $("#submitButton").show();
                        $("#submitShow").hide();
                        $("#orderlist_form")[0].reset();
                        
                    }
                });
                return false;
            });
        }
    });
});
</script>
</head>
<body style="background:#fff;font-size: 14px;">
    <div class="portlet-body">
        <form class="dataform" id="orderlist_form">
        	<input type="hidden" name="id" value="${ID }">
            <div class="row" style="height:15px;"></div>
            <div class="row">
                <label class="col-md-2" style="line-height:35px;">充值卡面值<b style="color:red;font-size:16px;">*</b>：</label>
                <div class="col-md-2">
                    <input type="checkbox" name="nation" value="1000" id="">&nbsp;&nbsp;1000面额
                </div>
                <div class="col-md-4" style="display: none;" id="cardp1000">
                    <div class="col-md-6"><input type="text" placeholder="请输入充值卡开始的卡号" class="form-control" name="cardps0"></div>
                    <div class="col-md-6"><input type="text" placeholder="请输入充值卡结束的卡号" class="form-control" name="cardpe0"></div>
                </div>
            </div>
            <!-- <div class="row" style="height:10px;"></div> -->
            <div class="row">
                <label class="col-md-2" style="line-height:35px;">&nbsp;&nbsp;</label>
                <div class="col-md-2">
                    <input type="checkbox" name="nation" value="500" id="">&nbsp;&nbsp;500面额
                </div>
                <div class="col-md-4" style="display: none;" id="cardp500">
                    <div class="col-md-6"><input type="text" placeholder="请输入充值卡开始的卡号" class="form-control" name="cardps1"></div>
                    <div class="col-md-6"><input type="text" placeholder="请输入充值卡结束的卡号" class="form-control" name="cardpe1"></div>
                </div>
            </div>
            <!-- <div class="row" style="height:10px;"></div> -->
            <div class="row">
                <label class="col-md-2" style="line-height:35px;">&nbsp;&nbsp;</label>
                <div class="col-md-2">
                    <input type="checkbox" name="nation" value="100" id="">&nbsp;&nbsp;100面额
                </div>
                <div class="col-md-4" style="display: none;" id="cardp100">
                    <div class="col-md-6"><input type="text" placeholder="请输入充值卡开始的卡号" class="form-control" name="cardps2"></div>
                    <div class="col-md-6"><input type="text" placeholder="请输入充值卡结束的卡号" class="form-control" name="cardpe2"></div>
                </div>
            </div>
            <div class="row" style="height:10px;"></div>
            <div class="row">
                <label class="col-md-2" style="line-height:35px;">&nbsp;&nbsp;释放日期&nbsp;<b style="color:red;font-size:16px;">*</b>：</label>
                <div class="col-md-2">
                    <input class="form-control" value="" name="releaseTime" onclick="WdatePicker()" placeholder="释放日期" type="text">
                </div>
            </div>
            <div class="row" style="height:10px;"></div>
            <div class="row">
                <label class="col-md-2" style="line-height:35px;">&nbsp;&nbsp;释放金额&nbsp;<b style="color:red;font-size:16px;">*</b>：</label>
                <div class="col-md-2">
                    <input type="text" class="form-control" name="releaseAmount" placeholder="请输入释放金额">
                </div>
            </div>
            <div class="row" style="">
                <div style="width:14%;height: 30px;display: inline-block;margin-left:10%;margin-top:20px;">
                    <input type="button" class="btn offline_serch_hide"
                        style="margin-right: 30px; background: #18BC9C; color: #fff; border-color: #18BC9C;"
                        value="保存" id="submitButton">
                    <input type="button" class="btn offline_serch_hide"
                        style="margin-right: 30px; background: #999; color: #fff; border-color: #999;display:none;"
                        value="保存中。。。" disabled="disabled" id="submitShow">
                </div>
            </div>
            <div style="width: 100%; height: 15px;"></div>
        </form>
    </div>
</body>
</html>